package Exception.Picture;

/**
 * 图片工具类
 */
public class PictureUtils {

    private PictureUtils() {}

    public static String checkAndRenamePicture(String pictureName) throws PictureException {

        boolean pngPicture = pictureName.endsWith(".png");
        boolean jpgPicture = pictureName.endsWith(".jpg");
        boolean jpegPicture = pictureName.endsWith(".jpeg");

        // 判断图片
        boolean isRight = pngPicture || jpgPicture || jpegPicture;
        if(!isRight) {
            throw new PictureException("图片类型不正确");
        }

        // 返回新名称
        String suffix = pictureName.substring(pictureName.lastIndexOf("."));
        String newName = System.currentTimeMillis() + suffix;
        return newName;
    }


}
